﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Collections.Generic;

namespace Delay
{
    public class SearchResultView : DependencyObject, INotifyPropertyChanged
    {
        public SearchResultView()
        {
            SearchResultItems = new ObservableCollection<phonePkItem>();
           
        }
       
        private string _key;
        public string Key
        {
            get
            {
                return _key;
            }
            set
            {
                if (_key != value)
                {
                    _key = value;
                    NotifyPropertyChanged("Key");
                }
            }
        }
        private string _defualt;
        public string Defualt
        {
            get
            {
                return _defualt;
            }
            set
            {
                if (_defualt != value)
                {
                    _defualt = value;
                    NotifyPropertyChanged("Defualt");
                }
            }
        }
        public int CurrentPage
        {
            get;
            set;
        }
        public int TotalPage
        {
            get;
            set;
        }
        public int PageSize
        {
            get;
            set;
        }
        public bool AllowAdd
        {
            get;
            set;
        }
        public string ClassName
        {
            get;
            set;
        }
        public int _result;
        public int Result
        {
            get
            {
                return _result;
            }
            set
            {
                if (_result != value)
                {
                    _result = value;
                    NotifyPropertyChanged("Result");
                }
            }
        }
        public string Message
        {
            get;
            set;
        }
        public string GetInitUrl(int sysytem)
        {
            string url = QueryXml.PhoneInitUrl;
            url += ("imei=" + QueryXml.imei);
            url += ("&phonename=" + QueryXml.phonename);
            url += ("&phonevs=" + QueryXml.phonevs);
            url += ("&phonevsno=" + QueryXml.phonevsno);
            url += ("&keyvalue=" + QueryXml.keyvalue);
            url += ("&channelkey=" + QueryXml.channelkey);
            url += ("&system=" + sysytem.ToString());
            return url;
        }
        public string GetInitUrl(string key)
        {
            string url = QueryXml.PhonedProfectSerchUrl;
            url += ("imei=" + QueryXml.imei);
            url += ("&phonename=" + QueryXml.phonename);
            url += ("&phonevs=" + QueryXml.phonevs);
            url += ("&phonevsno=" + QueryXml.phonevsno);
            url += ("&keyvalue=" + QueryXml.keyvalue);
            url += ("&channelkey=" + QueryXml.channelkey);
            url += ("&searchvalue=" + key);
            return url;
        }
        public string GetPhoneInfoUrl(IDictionary<string, string> parameters,int sort,int p)
        {
          //从字典资源里面取出字符串
            if (parameters==null)
            {
                return null;
            }
            string url;
            if (parameters.ContainsKey("ppid_1")==false)
            {
                url = QueryXml.PhoneSearchMoreUrl;
               
                url += ("imei=" + QueryXml.imei);
                url += ("&phonename=" + QueryXml.phonename);
                url += ("&phonevs=" + QueryXml.phonevs);
                url += ("&phonevsno=" + QueryXml.phonevsno);
                url += ("&keyvalue=" + QueryXml.keyvalue);
                url += ("&channelkey=" + QueryXml.channelkey);
                url += ("&p=" + p);
                url += ("&pagesize=" + PageSize);
                url += ("&total=" + TotalPage);
                if (parameters.ContainsKey("price"))
                {
                    url += ("&price=" + parameters["price"]);
                   
                }
                if (parameters.ContainsKey("ppname"))
                    {
                        url += ("&ppname=" + parameters["ppname"]);
                        //
                    }
                if (parameters.ContainsKey("system"))
                {
                    url += ("&system=" + parameters["system"]);
                }
               
                if (parameters.ContainsKey("stype"))
                {
                    url += ("&stype=" + parameters["stype"]);
                }
              
                if (parameters.ContainsKey("camera"))
                {
                    url += ("&camera=" + parameters["camera"]);
                }
                
                //
                if (parameters.ContainsKey("gps"))
                {
                    url += ("&gps=" + parameters["gps"]);
                }
                
                if (parameters.ContainsKey("wifi"))
                {
                    url += ("&wifi=" + parameters["wifi"]);
                }
               
                if (parameters.ContainsKey("carrier"))
                {
                    url += ("&carrier=" + parameters["carrier"]);
                }
               
                if (parameters.ContainsKey("markettime"))
                {
                    url += ("&markettime=" + parameters["markettime"]);
                }
               
                if (parameters.ContainsKey("ram"))
                {
                    url += ("&ram=" + parameters["ram"]);
                }
              
                if (parameters.ContainsKey("area"))
                {
                    url += ("&area=" + parameters["area"]);
                }
              
                if (parameters.ContainsKey("cpu"))
                {
                    url += ("&cpu=" + parameters["cpu"]);
                }
                //
              

                if (parameters.ContainsKey("distingwish"))
                {
                    url += ("&distingwish=" + parameters["distingwish"]);
                }
               
                if (parameters.ContainsKey("screensize"))
                {
                    url += ("&screensize=" + parameters["screensize"]);
                }
               
                if (parameters.ContainsKey("color"))
                {
                    url += ("&color=" + parameters["color"]);
                }
                url += ("&sort=" + sort.ToString());
            }
            else
            {

                 url = QueryXml.PhoneTypeSerchUrl;
                 url += ("imei=" + QueryXml.imei);
                 url += ("&phonename=" + QueryXml.phonename);
                 url += ("&phonevs=" + QueryXml.phonevs);
                 url += ("&phonevsno=" + QueryXml.phonevsno);
                 url += ("&keyvalue=" + QueryXml.keyvalue);
                 url += ("&channelkey=" + QueryXml.channelkey);
                 url += ("&p=" + p);
                 url += ("&pagesize=" + PageSize);
                 url += ("&total=" + TotalPage);
                 url += ("&ppid=") + parameters["ppid_1"];
                 if (sort == 0)
                 {//最新
                     url += "&sort=1";
                 }
                 else
                 {//最热
                     url += "&sort=2";
                 }
            }
            
            
         //添加一些与机型有关的参数
         //string make ;
           
          // string price ;
            

         return url;
        }
        public string GetPhoneInfoUrl(int sort)
        {
            string url = QueryXml.PhoneSearchMainUrl;
            url += ("imei=" + QueryXml.imei);
            url += ("&phonename=" + QueryXml.phonename);
            url += ("&phonevs=" + QueryXml.phonevs);
            url += ("&phonevsno=" + QueryXml.phonevsno);
            url += ("&keyvalue=" + QueryXml.keyvalue);
            url += ("&channelkey=" + QueryXml.channelkey);
            url += ("&sort=" + sort.ToString());
            return url;
        }
        public string GetPhoneInfoUrl(string classid,string sortby,int p)
        {
            string url = QueryXml.PhoneHotPhoneUrl;
            url += ("imei=" + QueryXml.imei);
            url += ("&phonename=" + QueryXml.phonename);
            url += ("&phonevs=" + QueryXml.phonevs);
            url += ("&phonevsno=" + QueryXml.phonevsno);
            url += ("&keyvalue=" + QueryXml.keyvalue);
            url += ("&channelkey=" + QueryXml.channelkey);
            //
            url += ("&p=" + p.ToString());
            url += ("&pagesize=" + this.PageSize);
            url += ("&total=" + this.TotalPage);
            //
            url += ("&classid=" + classid);
            url += ("&sortby=" + sortby);
            //
            return url;
        }
        public string GetPhoneInfoUrl(string ppid, string sort, int p, string leftchar)
        {
            string url = QueryXml.PhoneTypePhoneUrl;
            url += ("imei=" + QueryXml.imei);
            url += ("&phonename=" + QueryXml.phonename);
            url += ("&phonevs=" + QueryXml.phonevs);
            url += ("&phonevsno=" + QueryXml.phonevsno);
            url += ("&keyvalue=" + QueryXml.keyvalue);
            url += ("&channelkey=" + QueryXml.channelkey);
            //
            url += ("&p=" + p.ToString());
            url += ("&pagesize=" + this.PageSize);
            url += ("&total=" + this.TotalPage);
            //
            url += ("&ppid=" + ppid);
            url += ("&sort=" + sort);
                url += ("&leftchar=" + leftchar);
            return url;
        }
        private ObservableCollection<phonePkItem> _searchResultItems;
        public ObservableCollection<phonePkItem> SearchResultItems
        {
            get
            {
                return _searchResultItems;
            }
            set
            {
                if (_searchResultItems != value)
                {
                    _searchResultItems = value;
                    NotifyPropertyChanged("SearchResultItems");
                }
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
      
    }
}
